#include<bits/stdc++.h>
using namespace std;

vector<int> mp(25);

void init() {
    mp[6] = 10000;
    mp[7] = 36;
    mp[8] = 720;
    mp[9] = 360;
    mp[10] = 80;
    mp[11] = 252;
    mp[12] = 108;
    mp[13] = 72;
    mp[14] = 54;
    mp[15] = 180;
    mp[16] = 72;
    mp[17] = 180;
    mp[18] = 119;
    mp[19] = 36;
    mp[20] = 306;
    mp[21] = 1080;
    mp[22] = 144;
    mp[23] = 1800;
    mp[24] = 3600;
}


int cnt[10], a[5][5];

signed main() {

    init();

    for(int i = 1; i <= 3; i++) {
        for(int j = 1; j <= 3; j++) {
            cin >> a[i][j];
            cnt[a[i][j]] = 1;
        }
    }

    for(int i = 1; i <= 3; i++) {
        for(int j = 1; j <= 3; j++) {
            if(!a[i][j]) {
                for(int k = 1; k <= 9; k++) {
                    if(!cnt[k]) {
                        cnt[k] = 1;
                        a[i][j] = k;
                    }
                }
            }
        }
    }

    for(int i = 1; i <= 3; i++) {
        int x, y;
        cin >> x >> y;
        cout << a[x][y] << "\n";
    }

    int k;
    cin >> k;

    switch(k) {
        case 1:
            cout << mp[a[1][1] + a[1][2] + a[1][3]];
            break;
        case 2:
            cout << mp[a[2][1] + a[2][2] + a[2][3]];
            break;
        case 3:
            cout << mp[a[3][1] + a[3][2] + a[3][3]];
            break;
        case 4:
            cout << mp[a[1][1] + a[2][1] + a[3][1]];
            break;
        case 5:
            cout << mp[a[1][2] + a[2][2] + a[3][2]];
            break;
        case 6:
            cout << mp[a[1][3] + a[2][3] + a[3][3]];
            break;
        case 7:
            cout << mp[a[1][1] + a[2][2] + a[3][3]];
            break;
        case 8:
            cout << mp[a[1][3] + a[2][2] + a[3][1]];
            break;
    }

    return 0;
}

